﻿using Guest_room.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Guest_room
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }



        private void Button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public static bool flag = false;
        public static bool Aflag = false;
        public static string username, userid;
        GuestRoomService guestRoomService = new GuestRoomService();

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("请输入用户名或密码！");
            }
            else
            {
                string role = radioButton1.Checked ? "管理员" : "普通员工";
                bool isValidUser = guestRoomService.ValidateUser(textBox1.Text, textBox2.Text, role);

                if (isValidUser)
                {
                    MessageBox.Show("登录成功");

                    if (role == "管理员")
                    {
                        flag = true;
                        userid = textBox1.Text;
                        username = guestRoomService.GetUserName(textBox1.Text, role);
                        this.Close();
                        admin.index f = new admin.index();
                        f.Show();
                    }
                    else
                    {
                        Aflag = true;
                        userid = textBox1.Text;
                        username = guestRoomService.GetUserName(textBox1.Text, role);
                        this.Close();
                        Default f = new Default();
                        f.Show();
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                }
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void Login_Load(object sender, EventArgs e)
        {

        }
    }
}
